<?php
/**
 * 轻舟CMS(QZLOG)
 *
 * 一款基于PHP+MYSQL的开源内容管理系统，模板标签简单、可扩展性强，利于二次开发，轻松建站的首选利器。
 *
 * @package     QZLOG
 * @license     http://www.qzlog.com/license
 * @link        http://www.qzlog.com
 * @mail        info@shyohan.com
 * @since       Version 3.0
 * @copyright   Copyright (c) 2015 - 2017 上海优翰信息科技有限公司. All rights reserved.
 */

defined('IN_QZLOG') OR exit('QZLOG:No direct script access allowed!');

class IndexController extends QzController
{
    /**
     * 后台首页
     * @author LINK <link@shyohan.com>
     */
    public function index()
    {
        $menuList = $this->getMenus();
        $this->assign('menuList', $menuList);
        $this->display();
    }

    /**
     * 后台欢迎页
     * @author LINK <link@shyohan.com>
     */
    public function welcome()
    {
        $systemInfo = S('systemInfo');
        if (!S('systemInfo')) {
            $systemInfo = $this->systemInfo();
        }
        $this->assign('info', $systemInfo);
        $this->display();
    }

    /**
     * 获取系统信息
     * @author LINK <link@shyohan.com>
     * @return array
     */
    public function systemInfo()
    {
        //服务器信息
        $data = array();
        $data['version'] = C('QZLOG_VERSION');
        $is_ini_get = function_exists('ini_get');
        $data['os'] = function_exists('php_uname') ? php_uname() : '未知';
        $data['software'] = $_SERVER['SERVER_SOFTWARE'];
        $data['php'] = PHP_VERSION;
        $data['db_driver'] = C('DB_DRIVER');
        $data['mysql_version'] = M()->getVersion();
        $data['fileSize'] = $is_ini_get ? ini_get('upload_max_filesize') : '未知';
        $data['execTime'] = $is_ini_get ? ini_get('max_execution_time') : '未知';
        $data['safeMode'] = $is_ini_get ? (ini_get('safe_mode') ? 'Yes' : 'No') : '未知';
        $data['url_fopen'] = $is_ini_get ? (ini_get('allow_url_fopen') ? 'Yes' : 'No') : '未知';
        $data['other'] = $this->get_other();
        S('systemInfo', $data, 86400);
        return $data;
    }

    /**
     * 获取其他信息
     * @author LINK <link@shyohan.com>
     * @return string
     */
    private function get_other()
    {
        $s = '';
        if (function_exists('extension_loaded')) {
            if (extension_loaded('gd')) {
                function_exists('imagepng') && $s .= 'png ';
                function_exists('imagejpeg') && $s .= 'jpg ';
                function_exists('imagegif') && $s .= 'gif ';
            }
            extension_loaded('iconv') && $s .= 'iconv ';
            extension_loaded('mbstring') && $s .= 'mbstring ';
            extension_loaded('zlib') && $s .= 'zlib ';
            extension_loaded('ftp') && $s .= 'ftp ';
            function_exists('fsockopen') && $s .= 'fsockopen';
        }
        return $s;
    }

    /**
     * 获取后台菜单
     * @author LINK <link@shyohan.com>
     * @return bool
     */
    public function getMenus()
    {
        $menuList = S('menuList');
        if (!S('menuList')) {
            $menuList = $this->update_menus();
        }
        return $menuList;
    }
}
